<template>
  <div class="phoneLogin">
    <HeaderTitle :title="2"></HeaderTitle>
    <div class="content">
      <div class="logo">
        <img class="logoImg" src="https://yanxuan.nosdn.127.net/static-union/164793255107785e.png" alt="">
      </div>
      <div class="loginInfo">
        <van-cell-group inset>
          <van-field v-model="phone" placeholder="请输入手机号" />
        </van-cell-group>
        <van-cell-group inset>
          <van-field v-model="code" placeholder="请输入短信验证码" />
          <van-button class="codeBtn" type="default" @click="getCode">获取验证码</van-button>
        </van-cell-group>
        <div class="someText">
          <div class="err">遇到问题？</div>
          <div>使用密码验证登录</div>
        </div>
        <van-button class="submit" type="danger" @click="loginAndToCenter">登录</van-button>
        <div class="agreeOn">
          <input id="agree" v-model="checked" type="checkbox">
          <label for="agree">同意<a>《服务条款》</a>和<a>《隐私政策》</a>和<a>《网易严选服务协议》</a></label>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue"
export default defineComponent({
  name: 'phonelogin',
})
</script>

<script lang="ts" setup>
import HeaderTitle from "@/components/HeaderTitle/index.vue"
import { ref } from 'vue'
import { useRouter } from "vue-router";

import { showToast } from "vant";
const phone = ref('13456789000')
const code = ref('')
const checked = ref(true)

function getCode() {
  code.value = '123456'
}
const router = useRouter()
function loginAndToCenter() {
  if (phone.value.length === 11 && code.value.length === 6 && checked.value) {
    let userInfo = {
      phone:phone.value,
      code:code.value
    }
    localStorage.setItem('userInfo', JSON.stringify(userInfo))
    router.replace('/center')
  } else {
    showToast('请输入电话、验证码并勾选协议')
  }
}
</script>

<style lang="less" scoped>
.content {
  height: 433px;
  margin-top: 44px;
  border-top: 0.5px solid #d9d9da;

  .logo {
    height: 45px;
    margin-top: 28px;
    text-align: center;

    .logoImg {
      height: 45px;
    }
  }

  .loginInfo {
    margin-top: 30px;

    .codeBtn {
      padding: 0;
      font-size: 14px;
      font-weight: 500;
      border: 1px solid #7F7F7F;
      color: #333;
      width: 82px;
      height: 27px;
      position: relative;
      top: -36px;
      right: -252px;
    }

    .someText {
      margin: -6px 20px 0 20px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14.28px;
      color: #333;

      .err {
        color: #7F7F7F;
      }
    }

    .submit {
      width: 335px;
      height: 46px;
      line-height: 46px;
      margin: 16px 20px 0;
      font-size: 14.28px;
    }

    .agreeOn {
      width: 335px;
      height: 40px;
      margin: 8px 20px 0;
      display: flex;
      line-height: 20px;
      #agree{
        width: 17px;
        height: 17px;
        margin-right: 5px;
      }
      a{
        color: #397DF6;
        margin: 0 4px;
      }
    }
  }
}
:deep(.van-checkbox){
  width: 17px;
  height: 17px;
}

:deep(.van-cell-group) {
  margin-top: 20px;
}

:deep(.van-cell) {
  border-bottom: 1px solid #ECECEC;
  padding: 10px 12px 10px 6px;
}

:deep(.van-field__control::placeholder) {
  color: #7F7F7F;
}
</style>